package com.nsxy.common.config;

import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;

/**
 * 缓存配置
 * @author 潜行的青衣
 * @see
 */
@Order(20)
@Configuration
public class CacheConfig {

	@Bean
	public EhCacheCacheManager ehCacheCacheManager() {
		EhCacheCacheManager manager = new EhCacheCacheManager();
		manager.setCacheManager(ehcacheManagerFactory().getObject());
		return manager;
	}
	
	@Bean
	public EhCacheManagerFactoryBean ehcacheManagerFactory() {
		EhCacheManagerFactoryBean factory = new EhCacheManagerFactoryBean();
		factory.setConfigLocation(new ClassPathResource("ehcache.xml"));
		factory.setShared(true);
		return factory;
	}
	
}
